package com.basin.micro.auth.util;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * @author: Sam ZHONG | sammy1997@aliyun.com
 */
public final class PasswordUtil {
    private PasswordUtil() {
    }

    private static final BCryptPasswordEncoder PASSWORD_ENCODER = new BCryptPasswordEncoder();

    /**
     * 密码加密
     *
     * @param rawPassword 明文
     * @return 密文
     */
    public static String encodePassword(String rawPassword) {
        return PASSWORD_ENCODER.encode(rawPassword);
    }

    /**
     * 密码校验
     *
     * @param rawPassword     明文
     * @param encodedPassword 密文
     * @return 结果
     */
    public boolean checkPassword(String rawPassword, String encodedPassword) {
        return PASSWORD_ENCODER.matches(rawPassword, encodedPassword);
    }
}
